/*
 *  WsvJdbc - a JDBC driver for WSV (values separated by whatever) data files
 *  Copyright (C) 2004  Daniele Pes
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License as published by the Free Software Foundation; either
 *  version 2.1 of the License, or (at your option) any later version.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

package axs.jdbc.utils;


/**
 * This class is used to provide system utilities for the WsvJdbc driver.
 * 
 * @author  Pier Ribatto
 * @version    $Id: SysUtils.java,v 1.2 2007/04/16 17:24:37 montag451 Exp $
 */
public class SysUtils {
	// file separators with different OSs' JVMs
	// WINDOWS
	// os.name=            "Windows..."                   "windows..."		"\"	
	// LINUX
	// os.name=            "Linux"                        "linux"				"/"
	// MAC OS
	// os.name=            "Mac..."                       "mac..."				"/"	
	// SOLARIS
	// os.name=            "Solaris"                      "solaris"			"/"
	// OS/2
	// os.name=            "OS/2"                         "os/2"				"\"
	// OTHER UNIX SYSTEMS
		// MPE/iX
		// os.name=            "MPE/iX"                       "mpe/ix"			"/"
		// HP-UX
		// os.name=            "HP-UX"                        "hp-ux"			"/"
		// AIX 4.3
		// os.name=            "AIX"                          "aix"				"/"
		// FreeBSD
		// os.name=            "FreeBSD"                      "freebsd"		"/"
		// IRIX
		// os.name=            "Irix"                         "irix"			"/"
		// DIGITAL UNIX
		// os.name=            "Digital Unix"                 "digital unix"	"/"
	// NetWare
	// os.name=            "NetWare ..."                 "netware ..."		"\"
	
   private static final String  osName  = System.getProperty("os.name");
   
   private static final boolean windows = (osName.toUpperCase().indexOf("WINDOWS") != -1);
   private static final boolean linux   = (osName.toUpperCase().indexOf("LINUX") != -1);
	private static final boolean macos   = (osName.toUpperCase().indexOf("MAC") != -1);
	private static final boolean solaris = (osName.toUpperCase().indexOf("SOLARIS") != -1);
	private static final boolean os2 	 = (osName.toUpperCase().indexOf("OS/2") != -1);
	private static final boolean mpeix   = (osName.toUpperCase().indexOf("MPE/IX") != -1);
	private static final boolean hpux    = (osName.toUpperCase().indexOf("HP-UX") != -1);
	private static final boolean AIX     = (osName.toUpperCase().indexOf("AIX") != -1);
	private static final boolean freebsd = (osName.toUpperCase().indexOf("FREEBSD") != -1);
	private static final boolean IRIX    = (osName.toUpperCase().indexOf("IRIX") != -1);
	private static final boolean digunix = (osName.toUpperCase().indexOf("DIGITAL UNIX") != -1);
	private static final boolean netware = (osName.toUpperCase().indexOf("NETWARE") != -1);
   
   public static String getOsName() {
      return osName;
   }

   public static boolean isWindowsLike() {
      return windows || os2 || netware;
   }
   
   public static boolean isLinuxLike() {
      return linux || macos || solaris || mpeix || hpux || digunix || AIX || freebsd || IRIX;
   }
   
   public static String getWindowsLikePath(String path) {
      return path.replace('/','\\');
   }
   
   public static String getLinuxLikePath(String path) {
      return path.replace('\\','/');
   }
   
   public static String getPath(String path) {   	
      String result = isWindowsLike() 
                    ? getWindowsLikePath(path) 
                    : getLinuxLikePath(path);            
      return result;              
   }
}
